package com.zmzncs.lmtc.module.promotion.controller;


import com.zmzncs.lmtc.common.pojo.Rest;
import com.zmzncs.lmtc.common.util.JsonUtil;
import com.zmzncs.lmtc.common.util.RestUtil;
import com.zmzncs.lmtc.module.promotion.pojo.duration_rule_park.DurationRulePark;
import com.zmzncs.lmtc.module.promotion.pojo.duration_rule_park.DurationRuleParkDTO;
import com.zmzncs.lmtc.module.promotion.pojo.duration_rule_park.DurationRuleParkVO;
import com.zmzncs.lmtc.module.promotion.service.DurationRuleParkService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.constraints.NotNull;
import java.util.List;

/**
 * <p>
 * 促销-时长规则类型 前端控制器
 * </p>
 *
 * @author 任建波
 * @since 2020-08-12
 */
@Api(tags = "时长规则的停车场")
@RestController
@RequestMapping("/promotion/duration-rule-park")
@Validated
public class DurationRuleParkController {

    @Autowired
    DurationRuleParkService durationRuleParkService;

    @ApiOperation(value = "查询时长规则的停车场")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "header", name = "token", value = "请求头token", required = true),
    })
    @GetMapping(value = "getDurationRuleParkList")
    public Rest<List<DurationRuleParkVO>> getDurationRuleParkList() {
        List<DurationRulePark> durationRuleParkList = durationRuleParkService.list(null);
        List<DurationRuleParkVO> durationRuleParkVOList = JsonUtil.listTransform(durationRuleParkList, DurationRuleParkVO.class);
        return RestUtil.success(durationRuleParkVOList);
    }

    @ApiOperation(value = "根据parkId查询该停车场规则的其他停车场")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "header", name = "token", value = "请求头token", required = true),
            @ApiImplicitParam(paramType="query", name="parkId", value="停车场id", required = true),
            @ApiImplicitParam(paramType="query", name="keyword", value="搜索关键字"),
    })
    @GetMapping(value = "getDurationRuleParkByParkId")
    public Rest<List<DurationRuleParkVO>> getDurationRuleParkByParkId(@NotNull String parkId, String keyword) {
        List<DurationRuleParkDTO> durationRuleParkDTOList = durationRuleParkService.getDurationRuleParkByParkId(parkId, keyword);
        List<DurationRuleParkVO> durationRuleParkVOList = JsonUtil.listTransform(durationRuleParkDTOList, DurationRuleParkVO.class);
        return RestUtil.success(durationRuleParkVOList);
    }

    @ApiOperation(value = "根据时长规则id查询停车场")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "header", name = "token", value = "请求头token", required = true),
            @ApiImplicitParam(paramType="query", name="durationRuleId", value="时长规则id", required = true),
            @ApiImplicitParam(paramType="query", name="keyword", value="搜索关键字"),
    })
    @GetMapping(value = "getDurationRuleParkByRuleId")
    public Rest<List<DurationRuleParkVO>> getDurationRuleParkByRuleId(@NotNull Long durationRuleId, String keyword) {
        List<DurationRuleParkDTO> durationRuleParkDTOList = durationRuleParkService.getDurationRuleParkByRuleId(durationRuleId, keyword);
        List<DurationRuleParkVO> durationRuleParkVOList = JsonUtil.listTransform(durationRuleParkDTOList, DurationRuleParkVO.class);
        return RestUtil.success(durationRuleParkVOList);
    }

}

